package com.android.taskmanager;

 
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class ViewComponent extends BaseAdapter{
	
	private Integer[] mThumbIds = {
            R.drawable.icon, R.drawable.icon,
            R.drawable.icon, R.drawable.icon,
            R.drawable.icon, R.drawable.icon,
            R.drawable.icon, R.drawable.icon,
            R.drawable.icon, R.drawable.icon,
            R.drawable.icon, R.drawable.icon
    };
	private Integer[] mTitleIds = {
			R.string.m1, R.string.m2,
			R.string.m3, R.string.m4,
			R.string.m5, R.string.m6,
			R.string.m7, R.string.m8,
			R.string.m9, R.string.m10,
			R.string.m11, R.string.m12
	};
	
    private LayoutInflater mInflater;

	
	public ViewComponent(Context c){
		mInflater = LayoutInflater.from(c);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mThumbIds.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder view;
        if (convertView == null) {  // if it's not recycled,   
             convertView = mInflater.inflate(R.layout.view_component, null);
//           convertView.setLayoutParams(new GridView.LayoutParams(150, 120));
             convertView.setLayoutParams(new GridView.LayoutParams(80, 80));
          view = new ViewHolder();
             view.title = (TextView) convertView.findViewById(R.id.text_view);
             view.image = (ImageView )convertView.findViewById(R.id.image_view);
             convertView.setTag(view);
         } else {
             view = (ViewHolder) convertView.getTag();
         }
	    view.image.setAdjustViewBounds(true);
	    view.image.setScaleType(ImageView.ScaleType.CENTER_CROP);   
//	    holder.icon.setPadding(0, 8, 8, 8);
	    view.title.setText(mTitleIds[position]);
	    view.image.setImageResource(mThumbIds[position]);
	    return convertView;   
    }   
    class ViewHolder {
        TextView title;
        ImageView image;
    }

}
